{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "      P00000142  P00000242  P00000342  P00000442  P00000542  P00000642  \\\n",
      "0          True      False      False      False      False      False   \n",
      "1         False      False      False      False      False      False   \n",
      "2         False      False      False      False      False      False   \n",
      "3         False      False      False      False      False      False   \n",
      "4         False      False      False      False      False      False   \n",
      "5          True      False      False      False      False      False   \n",
      "6         False      False      False      False      False      False   \n",
      "7         False      False      False       True      False      False   \n",
      "8         False      False      False      False      False      False   \n",
      "9         False       True      False      False      False      False   \n",
      "10        False      False      False      False      False      False   \n",
      "11        False      False      False      False      False      False   \n",
      "12        False       True      False      False      False      False   \n",
      "13        False      False      False      False      False      False   \n",
      "14        False      False      False      False      False      False   \n",
      "15        False      False      False      False      False      False   \n",
      "16        False      False      False      False      False      False   \n",
      "17         True      False      False      False      False      False   \n",
      "18        False      False      False      False      False      False   \n",
      "19         True      False      False      False      False      False   \n",
      "20        False      False      False      False      False      False   \n",
      "21         True       True      False      False      False       True   \n",
      "22        False      False      False      False      False      False   \n",
      "23        False      False      False      False      False      False   \n",
      "24        False      False       True       True       True      False   \n",
      "25        False      False      False      False      False      False   \n",
      "26         True      False      False      False      False      False   \n",
      "27        False      False      False      False      False      False   \n",
      "28        False      False      False      False      False      False   \n",
      "29        False      False      False      False      False      False   \n",
      "...         ...        ...        ...        ...        ...        ...   \n",
      "5861      False      False      False      False      False      False   \n",
      "5862      False      False      False      False      False      False   \n",
      "5863      False      False      False      False      False      False   \n",
      "5864      False      False      False      False      False      False   \n",
      "5865      False      False      False      False      False      False   \n",
      "5866      False      False      False      False      False      False   \n",
      "5867      False      False      False      False      False      False   \n",
      "5868      False      False      False      False      False      False   \n",
      "5869      False      False      False      False      False      False   \n",
      "5870      False      False      False      False      False      False   \n",
      "5871      False      False      False      False      False      False   \n",
      "5872      False      False      False      False      False      False   \n",
      "5873      False      False      False      False      False      False   \n",
      "5874      False      False      False      False      False      False   \n",
      "5875       True      False      False      False      False      False   \n",
      "5876      False      False      False      False      False      False   \n",
      "5877      False      False      False      False      False      False   \n",
      "5878      False      False      False      False      False      False   \n",
      "5879      False      False      False      False      False      False   \n",
      "5880      False      False      False      False      False      False   \n",
      "5881      False      False      False      False      False       True   \n",
      "5882      False      False      False      False      False      False   \n",
      "5883      False      False      False      False      False      False   \n",
      "5884       True      False      False      False      False      False   \n",
      "5885      False      False      False      False      False      False   \n",
      "5886      False      False      False      False      False      False   \n",
      "5887      False      False      False      False      False      False   \n",
      "5888      False      False      False      False      False      False   \n",
      "5889      False      False      False      False      False      False   \n",
      "5890      False       True      False      False      False      False   \n",
      "\n",
      "      P00000742  P00000842  P00000942  P00001042    ...     P0098942  \\\n",
      "0         False      False      False      False    ...        False   \n",
      "1         False      False      False      False    ...        False   \n",
      "2         False      False      False      False    ...        False   \n",
      "3         False      False      False      False    ...        False   \n",
      "4         False      False      False      False    ...        False   \n",
      "5         False      False      False      False    ...        False   \n",
      "6         False      False      False      False    ...        False   \n",
      "7         False      False      False      False    ...        False   \n",
      "8         False      False      False      False    ...        False   \n",
      "9         False      False      False      False    ...        False   \n",
      "10        False      False      False      False    ...        False   \n",
      "11        False      False      False      False    ...        False   \n",
      "12        False      False      False       True    ...        False   \n",
      "13        False      False      False      False    ...        False   \n",
      "14        False      False      False      False    ...        False   \n",
      "15        False      False      False      False    ...        False   \n",
      "16        False      False      False      False    ...        False   \n",
      "17        False      False      False       True    ...        False   \n",
      "18        False      False      False      False    ...        False   \n",
      "19        False      False      False      False    ...        False   \n",
      "20        False      False      False       True    ...        False   \n",
      "21        False      False      False      False    ...        False   \n",
      "22        False      False      False      False    ...        False   \n",
      "23        False      False      False      False    ...        False   \n",
      "24         True      False      False      False    ...        False   \n",
      "25        False      False      False      False    ...        False   \n",
      "26        False      False      False      False    ...        False   \n",
      "27        False      False      False      False    ...        False   \n",
      "28        False      False      False      False    ...        False   \n",
      "29        False      False      False      False    ...        False   \n",
      "...         ...        ...        ...        ...    ...          ...   \n",
      "5861      False      False      False      False    ...        False   \n",
      "5862      False      False      False      False    ...        False   \n",
      "5863      False      False      False      False    ...        False   \n",
      "5864      False      False      False      False    ...        False   \n",
      "5865      False      False      False      False    ...        False   \n",
      "5866      False      False      False      False    ...        False   \n",
      "5867      False      False      False      False    ...        False   \n",
      "5868      False      False      False      False    ...        False   \n",
      "5869      False      False      False      False    ...        False   \n",
      "5870      False      False      False      False    ...        False   \n",
      "5871      False      False      False      False    ...        False   \n",
      "5872      False      False      False      False    ...        False   \n",
      "5873      False      False      False      False    ...        False   \n",
      "5874      False      False      False      False    ...        False   \n",
      "5875      False      False      False      False    ...        False   \n",
      "5876      False      False      False      False    ...        False   \n",
      "5877      False      False      False      False    ...        False   \n",
      "5878      False      False      False      False    ...        False   \n",
      "5879      False      False      False      False    ...        False   \n",
      "5880      False      False      False      False    ...        False   \n",
      "5881      False      False      False      False    ...        False   \n",
      "5882      False      False      False      False    ...        False   \n",
      "5883      False      False      False      False    ...        False   \n",
      "5884      False      False      False      False    ...        False   \n",
      "5885      False      False      False      False    ...        False   \n",
      "5886      False      False      False      False    ...        False   \n",
      "5887      False      False      False      False    ...        False   \n",
      "5888      False      False       True      False    ...        False   \n",
      "5889      False      False      False      False    ...        False   \n",
      "5890      False      False      False      False    ...        False   \n",
      "\n",
      "      P0099042  P0099142  P0099242  P0099342  P0099442  P0099642  P0099742  \\\n",
      "0        False     False     False     False     False     False     False   \n",
      "1        False     False     False     False     False     False     False   \n",
      "2        False     False     False     False     False     False     False   \n",
      "3        False     False     False     False     False     False     False   \n",
      "4        False     False     False     False     False     False     False   \n",
      "5        False     False     False     False     False     False     False   \n",
      "6        False     False     False     False     False     False     False   \n",
      "7        False     False     False     False     False     False     False   \n",
      "8        False     False     False     False     False     False     False   \n",
      "9        False     False     False     False     False     False     False   \n",
      "10       False     False     False     False     False     False     False   \n",
      "11       False     False     False     False     False     False     False   \n",
      "12       False     False     False     False     False     False     False   \n",
      "13       False     False     False     False     False     False     False   \n",
      "14       False     False     False     False     False     False     False   \n",
      "15       False     False     False     False     False     False     False   \n",
      "16       False     False     False     False     False     False     False   \n",
      "17       False     False     False     False     False     False     False   \n",
      "18       False     False     False     False     False     False     False   \n",
      "19       False     False     False     False     False     False     False   \n",
      "20       False     False     False     False     False     False     False   \n",
      "21       False     False     False     False     False     False     False   \n",
      "22        True     False     False     False     False     False     False   \n",
      "23       False     False     False     False     False     False     False   \n",
      "24       False     False     False     False     False     False     False   \n",
      "25       False     False     False     False     False     False     False   \n",
      "26       False     False     False     False     False     False     False   \n",
      "27       False     False     False     False     False     False     False   \n",
      "28       False     False     False     False     False     False     False   \n",
      "29       False     False     False     False     False     False     False   \n",
      "...        ...       ...       ...       ...       ...       ...       ...   \n",
      "5861     False     False     False     False     False     False     False   \n",
      "5862     False     False     False     False     False     False     False   \n",
      "5863     False     False     False     False     False     False     False   \n",
      "5864     False     False     False     False     False     False     False   \n",
      "5865     False     False     False     False     False     False     False   \n",
      "5866     False     False     False     False     False     False     False   \n",
      "5867     False     False     False     False     False     False     False   \n",
      "5868     False     False     False     False     False     False     False   \n",
      "5869     False     False     False     False     False     False     False   \n",
      "5870     False     False     False     False     False     False     False   \n",
      "5871     False     False     False     False     False     False     False   \n",
      "5872     False     False     False     False     False     False     False   \n",
      "5873     False     False     False     False     False     False     False   \n",
      "5874     False     False     False     False     False     False     False   \n",
      "5875     False     False     False     False     False     False     False   \n",
      "5876     False     False     False     False     False     False     False   \n",
      "5877     False     False     False     False     False     False     False   \n",
      "5878     False     False     False     False     False     False     False   \n",
      "5879     False     False     False     False     False     False     False   \n",
      "5880     False     False     False     False     False     False     False   \n",
      "5881     False     False     False     False     False     False     False   \n",
      "5882     False     False     False     False     False     False     False   \n",
      "5883     False     False     False     False     False     False     False   \n",
      "5884     False     False     False     False     False     False     False   \n",
      "5885     False     False     False     False     False     False     False   \n",
      "5886     False     False     False     False     False     False      True   \n",
      "5887     False     False     False     False     False     False     False   \n",
      "5888     False     False     False     False     False     False     False   \n",
      "5889     False     False     False     False     False     False     False   \n",
      "5890     False     False     False     False     False     False     False   \n",
      "\n",
      "      P0099842  P0099942  \n",
      "0        False     False  \n",
      "1        False     False  \n",
      "2        False     False  \n",
      "3        False     False  \n",
      "4        False     False  \n",
      "5        False     False  \n",
      "6        False     False  \n",
      "7        False     False  \n",
      "8        False     False  \n",
      "9        False     False  \n",
      "10       False     False  \n",
      "11       False     False  \n",
      "12       False     False  \n",
      "13       False     False  \n",
      "14       False     False  \n",
      "15       False     False  \n",
      "16       False     False  \n",
      "17       False     False  \n",
      "18       False     False  \n",
      "19       False     False  \n",
      "20       False     False  \n",
      "21       False     False  \n",
      "22       False     False  \n",
      "23       False     False  \n",
      "24       False     False  \n",
      "25       False     False  \n",
      "26       False     False  \n",
      "27       False     False  \n",
      "28       False     False  \n",
      "29       False     False  \n",
      "...        ...       ...  \n",
      "5861     False     False  \n",
      "5862     False     False  \n",
      "5863     False     False  \n",
      "5864     False     False  \n",
      "5865     False     False  \n",
      "5866     False     False  \n",
      "5867     False     False  \n",
      "5868     False     False  \n",
      "5869     False     False  \n",
      "5870     False     False  \n",
      "5871     False     False  \n",
      "5872     False     False  \n",
      "5873     False     False  \n",
      "5874     False     False  \n",
      "5875     False     False  \n",
      "5876     False     False  \n",
      "5877     False     False  \n",
      "5878     False     False  \n",
      "5879     False     False  \n",
      "5880     False     False  \n",
      "5881     False     False  \n",
      "5882     False     False  \n",
      "5883     False     False  \n",
      "5884     False     False  \n",
      "5885     False     False  \n",
      "5886     False     False  \n",
      "5887     False     False  \n",
      "5888     False     False  \n",
      "5889     False     False  \n",
      "5890     False     False  \n",
      "\n",
      "[5891 rows x 3623 columns]\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "df=pd.read_csv(\"D:\\study\\data\\project\\cleaned.csv\")\n",
    "lst=[]\n",
    "for item in df['User_ID'].unique():\n",
    "    lst2=list(set(df[df['User_ID']==item]['Product_ID']))\n",
    "    if len(lst2)>0:\n",
    "        lst.append(lst2)\n",
    "from mlxtend.preprocessing import TransactionEncoder\n",
    "from mlxtend.frequent_patterns import apriori, association_rules\n",
    "\n",
    "te=TransactionEncoder()\n",
    "te_data=te.fit(lst).transform(lst)\n",
    "df_x=pd.DataFrame(te_data,columns=te.columns_)\n",
    "print(df_x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "       support                           itemsets\n",
      "0     0.191818                        (P00000142)\n",
      "1     0.062977                        (P00000242)\n",
      "2     0.040401                        (P00000342)\n",
      "3     0.086912                        (P00000642)\n",
      "4     0.040401                        (P00000742)\n",
      "5     0.083857                        (P00001042)\n",
      "6     0.097097                        (P00001142)\n",
      "7     0.059243                        (P00001642)\n",
      "8     0.076218                        (P00001742)\n",
      "9     0.123578                        (P00002142)\n",
      "10    0.055169                        (P00002442)\n",
      "11    0.090307                        (P00002542)\n",
      "12    0.140893                        (P00003242)\n",
      "13    0.161433                        (P00003442)\n",
      "14    0.085384                        (P00003642)\n",
      "15    0.123918                        (P00003942)\n",
      "16    0.046681                        (P00004542)\n",
      "17    0.100323                        (P00004742)\n",
      "18    0.162112                        (P00005042)\n",
      "19    0.045663                        (P00005742)\n",
      "20    0.049397                        (P00006142)\n",
      "21    0.084026                        (P00006942)\n",
      "22    0.059243                        (P00009342)\n",
      "23    0.059073                        (P00010242)\n",
      "24    0.225938                        (P00010742)\n",
      "25    0.112375                        (P00010842)\n",
      "26    0.051434                        (P00010942)\n",
      "27    0.059413                        (P00013742)\n",
      "28    0.112884                        (P00014542)\n",
      "29    0.053132                        (P00014642)\n",
      "...        ...                                ...\n",
      "4480  0.040061  (P00270942, P00046742, P00110742)\n",
      "4481  0.040910  (P00046742, P00112142, P00145042)\n",
      "4482  0.041080  (P00270942, P00046742, P00145042)\n",
      "4483  0.041249  (P00110942, P00057642, P00110742)\n",
      "4484  0.046002  (P00112142, P00057642, P00110742)\n",
      "4485  0.044135  (P00057642, P00114942, P00110742)\n",
      "4486  0.041080  (P00057642, P00145042, P00110742)\n",
      "4487  0.044305  (P00057642, P00237542, P00110742)\n",
      "4488  0.043796  (P00270942, P00057642, P00110742)\n",
      "4489  0.040061  (P00110942, P00114942, P00057642)\n",
      "4490  0.041759  (P00112142, P00145042, P00057642)\n",
      "4491  0.043796  (P00112142, P00057642, P00237542)\n",
      "4492  0.041249  (P00270942, P00112142, P00057642)\n",
      "4493  0.040231  (P00057642, P00114942, P00237542)\n",
      "4494  0.040401  (P00270942, P00057642, P00114942)\n",
      "4495  0.043965  (P00057642, P00145042, P00237542)\n",
      "4496  0.048718  (P00270942, P00057642, P00145042)\n",
      "4497  0.045154  (P00270942, P00057642, P00237542)\n",
      "4498  0.040570  (P00059442, P00058042, P00184942)\n",
      "4499  0.042607  (P00059442, P00265242, P00058042)\n",
      "4500  0.040910  (P00112142, P00110842, P00110742)\n",
      "4501  0.042438  (P00110942, P00112142, P00110742)\n",
      "4502  0.041759  (P00112542, P00112142, P00110742)\n",
      "4503  0.043456  (P00112142, P00114942, P00110742)\n",
      "4504  0.042438  (P00112142, P00110742, P00117942)\n",
      "4505  0.043286  (P00112142, P00145042, P00110742)\n",
      "4506  0.040740  (P00112142, P00184942, P00110742)\n",
      "4507  0.042777  (P00112142, P00237542, P00110742)\n",
      "4508  0.040740  (P00270942, P00112142, P00110742)\n",
      "4509  0.040061  (P00270942, P00145042, P00237542)\n",
      "\n",
      "[4510 rows x 2 columns]\n"
     ]
    }
   ],
   "source": [
    "frequent_items=apriori(df_x,use_colnames=True,min_support=0.04)\n",
    "print(frequent_items)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "    antecedents consequents  antecedent support  consequent support   support  \\\n",
      "168   P00127442   P00032042            0.089798            0.092344  0.041928   \n",
      "169   P00032042   P00127442            0.092344            0.089798  0.041928   \n",
      "184   P00034042   P00303342            0.097267            0.098625  0.040570   \n",
      "183   P00303342   P00034042            0.098625            0.097267  0.040570   \n",
      "742   P00127442   P00125942            0.089798            0.121202  0.045833   \n",
      "167   P00032042   P00125942            0.092344            0.121202  0.044984   \n",
      "760   P00127742   P00127642            0.083178            0.126804  0.040231   \n",
      "761   P00127842   P00127642            0.101171            0.126804  0.045154   \n",
      "369   P00193542   P00057942            0.102869            0.131387  0.046002   \n",
      "447   P00100942   P00106042            0.085215            0.151417  0.043456   \n",
      "868   P00182242   P00182142            0.096418            0.151248  0.048718   \n",
      "738   P00193542   P00120042            0.102869            0.151417  0.051095   \n",
      "411   P00303342   P00070042            0.098625            0.124088  0.040061   \n",
      "153   P00030842   P00140742            0.099474            0.132575  0.042438   \n",
      "841   P00303342   P00147942            0.098625            0.151757  0.046172   \n",
      "206   P00216142   P00036842            0.094042            0.146834  0.042268   \n",
      "\n",
      "     confidence      lift  leverage  conviction  \n",
      "168    0.466919  5.056283  0.033636    1.702659  \n",
      "169    0.454044  5.056283  0.033636    1.667171  \n",
      "184    0.417103  4.229180  0.030977    1.546371  \n",
      "183    0.411360  4.229180  0.030977    1.533590  \n",
      "742    0.510397  4.211132  0.034949    1.794920  \n",
      "167    0.487132  4.019183  0.033792    1.713499  \n",
      "760    0.483673  3.814351  0.029684    1.691171  \n",
      "761    0.446309  3.519685  0.032325    1.577046  \n",
      "369    0.447195  3.403649  0.032487    1.571282  \n",
      "447    0.509960  3.367910  0.030553    1.731660  \n",
      "868    0.505282  3.340757  0.034135    1.715627  \n",
      "738    0.496700  3.280334  0.035519    1.686036  \n",
      "411    0.406196  3.273464  0.027823    1.475087  \n",
      "153    0.426621  3.217958  0.029250    1.512830  \n",
      "841    0.468158  3.084923  0.031205    1.594917  \n",
      "206    0.449458  3.060994  0.028459    1.549685  \n"
     ]
    }
   ],
   "source": [
    "rules=association_rules(frequent_items,metric='confidence',min_threshold=0.4)\n",
    "rules.antecedents=rules.antecedents.apply(lambda x: next(iter(x)))\n",
    "rules.consequents=rules.consequents.apply(lambda x: next(iter(x)))\n",
    "rules=rules.sort_values('lift',ascending=False)\n",
    "print(rules[rules.lift.apply(lambda x:x>=3)])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<script type=\"text/javascript\">window.PlotlyConfig = {MathJaxConfig: 'local'};</script><script type=\"text/javascript\">if (window.MathJax) {MathJax.Hub.Config({SVG: {font: \"STIX-Web\"}});}</script><script>requirejs.config({paths: { 'plotly': ['https://cdn.plot.ly/plotly-latest.min']},});if(!window._Plotly) {require(['plotly'],function(plotly) {window._Plotly=plotly;});}</script>"
      ],
      "text/vnd.plotly.v1+html": [
       "<script type=\"text/javascript\">window.PlotlyConfig = {MathJaxConfig: 'local'};</script><script type=\"text/javascript\">if (window.MathJax) {MathJax.Hub.Config({SVG: {font: \"STIX-Web\"}});}</script><script>requirejs.config({paths: { 'plotly': ['https://cdn.plot.ly/plotly-latest.min']},});if(!window._Plotly) {require(['plotly'],function(plotly) {window._Plotly=plotly;});}</script>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "'file://D:\\\\program\\\\python\\\\Scripts\\\\association_rules.html'"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import plotly.plotly as py\n",
    "import plotly.graph_objs as go\n",
    "from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot\n",
    "\n",
    "init_notebook_mode(connected=True)\n",
    "\n",
    "import networkx as nx\n",
    "\n",
    "nx_data=rules[rules.lift>=3]\n",
    "GA=nx.from_pandas_edgelist(nx_data,source='antecedents',target='consequents',edge_attr='lift')\n",
    "pos=nx.kamada_kawai_layout(GA,weight='lift')\n",
    "# pos = nx.nx_agraph.graphviz_layout(GA)\n",
    "# pos = nx.nx_agraph.graphviz_layout(GA, prog='dot')\n",
    "\n",
    "edge_trace = go.Scatter(\n",
    "    x=[],\n",
    "    y=[],\n",
    "    line=dict(width=0.5,color='#888'),\n",
    "    hoverinfo='none',\n",
    "    mode='lines')\n",
    "\n",
    "for edge in GA.edges():\n",
    "    x0, y0 = pos[edge[0]]\n",
    "    x1, y1 = pos[edge[1]]\n",
    "    edge_trace['x'] += tuple([x0, x1, None])\n",
    "    edge_trace['y'] += tuple([y0, y1, None])\n",
    "\n",
    "node_trace = go.Scatter(\n",
    "    x=[],\n",
    "    y=[],\n",
    "    text=[],\n",
    "    mode='markers',\n",
    "    hoverinfo='text',\n",
    "    marker=dict(\n",
    "        showscale=True,\n",
    "        colorscale='YlGnBu',\n",
    "        reversescale=True,\n",
    "        color=[],\n",
    "        size=10,\n",
    "        colorbar=dict(\n",
    "            thickness=15,\n",
    "            title='Node Connections',\n",
    "            xanchor='left',\n",
    "            titleside='right'\n",
    "        ),\n",
    "        line=dict(width=2)))\n",
    "\n",
    "for node in GA.nodes():\n",
    "    x, y = pos[node]\n",
    "    node_trace['x'] += tuple([x])\n",
    "    node_trace['y'] += tuple([y])\n",
    "\n",
    "for node,adjacencies in enumerate(GA.adjacency()):\n",
    "    node_trace['marker']['color']+=tuple([len(adjacencies[1])])\n",
    "    node_info = str(adjacencies[0])+' - # of connections: '+str(len(adjacencies[1]))\n",
    "    node_trace['text']+=tuple([node_info])\n",
    "    \n",
    "fig = go.Figure(data=[edge_trace, node_trace],\n",
    "             layout=go.Layout(\n",
    "                title='<br>association_rules graph',\n",
    "                titlefont=dict(size=16),\n",
    "                showlegend=False,\n",
    "                hovermode='closest',\n",
    "                margin=dict(b=20,l=5,r=5,t=40),\n",
    "                annotations=[ dict(\n",
    "                    text=\"Python code: <a href='https://plot.ly/ipython-notebooks/network-graphs/'> https://plot.ly/ipython-notebooks/network-graphs/</a>\",\n",
    "                    showarrow=False,\n",
    "                    xref=\"paper\", yref=\"paper\",\n",
    "                    x=0.005, y=-0.002 ) ],\n",
    "                xaxis=dict(showgrid=False, zeroline=False, showticklabels=False),\n",
    "                yaxis=dict(showgrid=False, zeroline=False, showticklabels=False)))\n",
    "plot(fig, filename='association_rules.html')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "pd.DataFrame(frequent_items).to_csv('frequent_items.csv')\n",
    "inter_rules=rules[rules.lift.apply(lambda x:x>=3)]\n",
    "pd.DataFrame(inter_rules).to_csv('inter_rules.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
